﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Billing
{
    /// <summary>
    /// Summary description for DataValueBase.
    /// </summary>
    public class BooleanBase
    {
        //Variables
        public bool Value = false;
        public bool Enabled = false;
        //Constructors
        public BooleanBase()
        { }
        public BooleanBase(bool Value)
            : this(Value, true)
        { }
        public BooleanBase(bool Value, bool Enabled)
        {
            this.Value = Value;
            this.Enabled = Enabled;
        }
        //Functions
        public void On() { this.Value = true; }
        public void Off() { this.Value = false; }
        public void Enable() { this.Enabled = true; }
        public void Disable() { this.Enabled = false; }
        public void Disable(bool Value) { this.Enabled = false; this.Off(); }
    }

    public class DataValueBase
    {
        public Guid GUID;
        public string KEY;
        public string NAME;
        public string TABLE;
        public string VIEW;
        public bool Updated = false;
        public DataValueBase()
        {
        }
        public DataValueBase(Guid DataGUID, string DataKEY, string DataNAME, string DataTABLE, string DataVIEW)
        {
            this.GUID = DataGUID;
            this.KEY = DataKEY;
            this.NAME = DataNAME;
            this.TABLE = DataTABLE;
            this.VIEW = DataVIEW;
        }
        public DataValueBase Clone()
        {
            return new DataValueBase(this.GUID, this.KEY, this.NAME, this.TABLE, this.VIEW);
        }
        public string SQLSelect()
        {
            return SQLSelect("");
        }
        public string SQLSelect(string WhereCondition)
        {
            return SQLSelect("", WhereCondition);
        }
        public string SQLSelect(string FieldList, string WhereCondition)
        {
            if (WhereCondition.Trim() != "") WhereCondition = "AND" + WhereCondition;
            if (FieldList.Trim() != "") FieldList = "," + FieldList;

            return
                "SELECT TOP 100 PERCENT " + "[" + this.KEY + "GUID]," + "[" + this.KEY + "KEY]," + "[" + this.KEY + "NAME] " + FieldList + " " +
                "FROM " + (String.IsNullOrEmpty(this.VIEW) ? this.TABLE : this.VIEW) + " " +
                "WHERE 1=1 " + WhereCondition + " " +
                "ORDER BY [" + this.KEY + "SID]";
        }

    }
}
